package model;

import java.util.Observable;

import model.collisions2d.MultipleBoxMask;
import datacontainers.Location2D;

/**
 * Models a generic object from the game model in 2D space
 * @author SwiftPengu
 *
 */
public class ModelObject extends Observable{
	private Location2D loc;
	
	/** speed in units per step */
	private double speed = 0;
	/** direction in degrees */
	private short direction = 0;
	
	private final MultipleBoxMask mask;
	
	protected ModelObject(Location2D start,MultipleBoxMask mask){
		this.loc = start;
		this.mask=mask;
	}
	
	public Location2D getLocation(){
		return loc;
	}
	
	public void setLocation(Location2D newloc){
		if(loc != newloc){
			setChanged();
			loc = newloc;
		}
		notifyObservers();
	}
	
	public double getSpeed(){
		return speed;
	}
	
	public void setSpeed(double newspeed){
		this.speed=newspeed;
	}
	
	public void setDirection(int newdir){
		this.direction=(short)(newdir%360);
	}
	
	public void setDirectionRadians(double newdir){
		this.direction = (short)(((newdir*180)/Math.PI)%360);
	}
	
	public double getDirection(){
		return direction;
	}
	
	public double getHorizontalSpeed(){
		return Math.cos((Math.PI*direction)/180)*speed;
	}
	
	public double getVerticalSpeed(){
		return -Math.sin((Math.PI*direction)/180)*speed;
	}
	
	public MultipleBoxMask getMask(){
		return mask;
	}
}
